Skip to content

fix(auth): add rate limiting for login and signup endpoints#553

Open
Ridanshi wants to merge 1 commit into
GitMetricsLab:mainfrom
Ridanshi:fix/auth-rate-limiting
Open

fix(auth): add rate limiting for login and signup endpoints#553
Ridanshi wants to merge 1 commit into
GitMetricsLab:mainfrom
Ridanshi:fix/auth-rate-limiting

Conversation

@Ridanshi
Copy link
Copy Markdown
Contributor

Closes #452

Summary

Adds focused authentication rate limiting for sensitive auth endpoints using express-rate-limit.

Previously, authentication endpoints had no throttling or abuse protection, allowing:

  • unlimited credential stuffing attempts
  • brute-force login attacks
  • password spraying
  • and bcrypt-driven CPU exhaustion attacks

Because every login request reached synchronous bcryptjs password verification with no request throttling.

This PR introduces scoped rate limiting for authentication-sensitive routes while preserving the existing auth/session behavior and response contracts.


Implementation

Added express-rate-limit and configured dedicated auth limiters for:

  • POST /api/auth/login
  • POST /api/auth/signup

Limiter configuration:

windowMs: 15 * 60 * 1000
max: 10
standardHeaders: true
legacyHeaders: false

Key changes:

  • added auth-specific request throttling
  • enabled standard rate-limit headers
  • disabled legacy rate-limit headers
  • preserved existing auth route behavior
  • preserved existing login/signup response contracts
  • avoided global middleware throttling

The limiter is intentionally scoped only to authentication-sensitive routes.


Files Changed

  • backend/config/authRateLimit.js
  • backend/routes/auth.js
  • backend/package.json
  • package.json
  • spec/auth.rate-limit.spec.cjs

Security Improvements

This reduces exposure to:

  • credential stuffing attacks
  • automated brute-force attempts
  • password spraying
  • event-loop degradation from repeated bcrypt operations
  • automated authentication abuse

Excessive requests now return:

429 Too Many Requests

with standard rate-limit headers enabled.


Tests

Focused regression coverage added for:

  • login limiter blocks excessive requests
  • signup limiter blocks excessive requests
  • HTTP 429 responses returned correctly
  • standard rate-limit headers present
  • legitimate requests still succeed under threshold

Verification

npx.cmd jasmine spec/auth.rate-limit.spec.cjs

Result:

5 specs, 0 failures

Full backend suite was also attempted:

npm.cmd run test:backend

Existing unrelated MongoDB-dependent auth/model specs timed out locally, while all newly-added auth rate-limit tests passed successfully.


Notes

This PR intentionally keeps scope limited to authentication abuse protection.

No CAPTCHA, Redis, account-lockout system, auth architecture rewrite, or unrelated middleware refactors were introduced.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 9676a4e
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a15f6edb01c3600084cfd1e
😎 Deploy Preview https://deploy-preview-553--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@Ridanshi, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 46 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10816eac-73b4-4a10-9979-bb288df1ffbb

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae0ef6 and 9676a4e.

📒 Files selected for processing (5)
  • backend/config/authRateLimit.js
  • backend/package.json
  • backend/routes/auth.js
  • package.json
  • spec/auth.rate-limit.spec.cjs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: POST /api/auth/login Has No Rate Limiting — Brute Force and bcrypt-Driven DoS Are Both Viable

1 participant